package junior.db.dao;

import junior.db.dao.base.IBaseId;
import junior.db.dao.jdbc.JdbcDao;
import junior.db.dao.mybatis.base.BaseMapper;
import junior.db.dao.mybatis.base.BaseSelectMapper;
import junior.db.dao.mybatis.mapper.EntityMapper;

/**
 * @author wubo
 * @date 2024/9/6 14:07
 */
public class BaseMapperFactory {
    private JdbcDao jdbcDao;
    private EntityMapper entityMapper;
    
    public BaseMapperFactory(JdbcDao jdbcDao) {
        this.jdbcDao = jdbcDao;
    }
    
    public BaseMapperFactory(EntityMapper entityMapper) {
        this.entityMapper = entityMapper;
    }
    
    public <E extends IBaseId, ID> BaseMapper<E, ID> createMapper(Class<E> entityClass, Class<ID> idClass) {
        if (jdbcDao != null) {
            return new JdbcMapperImpl<>(jdbcDao, entityClass, idClass);
        }
        return new MybatisMapperImpl(entityMapper, entityClass, idClass);
    }
    
    public <E extends IBaseId> BaseSelectMapper<E> createSelectMapper(Class<E> entityClass) {
        if (jdbcDao != null) {
            return new JdbcSelectMapperImpl<>(jdbcDao, entityClass);
        }
        return new MybatisSelectMapperImpl(entityMapper, entityClass);
    }
}
